home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / cdity / availmem2.lha / AvailMem2 / src / AvailMem2_main.s < prev    next >
Text File  |  1997-07-01  |  21KB  |  769 lines

  1.  
  2.     machine 68020
  3.  
  4.  
  5.     * program includes
  6.  
  7.     include    "AvailMem2_gui.i"
  8.     include    "AvailMem2.i"
  9.     include    "lvo.i"
  10.  
  11.     incdir    "include:"
  12.  
  13.     include    "exec/types.i"
  14.     include    "exec/execbase.i"
  15.     include    "exec/memory.i"
  16.     include    "exec/funcdef.i"
  17.     include    "dos/dos.i"
  18.     include    "dos/dosextens.i"
  19.     include    "libraries/commodities.i"
  20.     include    "workbench/workbench.i"
  21.     include    "workbench/startup.i"
  22.     include    "libraries/sysinfo.i"
  23.     include    "libraries/sysinfo_lib.i"
  24.  
  25.     * program defines
  26.  
  27. _SysBase        equ    (4).w    ;execbase constant
  28.  
  29. KICKVER            equ    37    ;require OS2.0+
  30. CONFVER            equ    1    ;config-version
  31.  
  32. CX_POPKEY        equ    1    ;CX GUI Popup key
  33.  
  34.     section    code,code        ;availmem code section
  35.  
  36. prg_Startup
  37.  
  38.     move.l    (4).w,a6        ;put execbase in a6
  39.     sub.l    a1,a1            ;clear a1
  40.     jsr    _LVOFindTask(a6)    ;find this task
  41.     move.l    d0,ptr_ThisTask        ;store taskptr
  42.  
  43.     move.l    ptr_ThisTask,a4        ;put pointer to task in a4
  44.     tst.l    pr_CLI(a4)        ;check if started from CLI
  45.     bne    .StartedFromCLI        ;skip if launched from CLI
  46.  
  47.     lea.l    pr_MsgPort(a4),a0    ;get ptr to msgport
  48.     jsr    _LVOWaitPort(a6)    ;wait for msg-port
  49.     lea.l    pr_MsgPort(a4),a0    ;get ptr to msgport
  50.     jsr    _LVOGetMsg(a6)        ;get waiting startup-message
  51.     move.l    d0,ptr_StartupMsg    ;store wbmessage
  52.  
  53. .StartedFromCLI
  54.  
  55.     move.l    (4).w,a6        ;put execbase in a6
  56.     move.l    ptr_ThisTask,a1        ;put ptr to task in a1
  57.     move.l    #-30,d0            ;Set low priority
  58.     jsr    _LVOSetTaskPri(a6)    ;set task priority
  59.     move.l    d0,prg_OldPriority    ;store old priority
  60.  
  61.     move.l    (4).w,a6        ;put execbase in a6
  62.     lea.l    _LibraryList,a4        ;get pointer to list of libraries
  63. .OpenLibraries
  64.     move.l    (a4)+,a1        ;get pointer to lib-string into a1
  65.     move.l    (a4)+,a3        ;get pointer to libbase-var
  66.  
  67.     move.l    a1,d0            ;put string-pointer in d0
  68.     tst.l    d0            ;check if no libs left
  69.     beq    .AllLibrariesOpen    ;leave loop if so
  70.  
  71.     move.l    #KICKVER,d0        ;set kick-version
  72.     jsr    _LVOOpenLibrary(a6)    ;open library
  73.     move.l    d0,(a3)            ;store library base
  74.     tst.l    d0            ;check if opened ok
  75.     beq    prg_Fail        ;bail out if failure
  76.  
  77.     bra    .OpenLibraries        ;loop lib-opening
  78.  
  79. .AllLibrariesOpen
  80.  
  81.     * open not essential libraries
  82.  
  83.     move.l    (4).w,a6        ;put execbase in a6
  84.     lea.l    _IconName,a1        ;get ptr to icon.library
  85.     move.l    #KICKVER,d0        ;put kick version in d0
  86.     jsr    _LVOOpenLibrary(a6)    ;open icon.library
  87.     move.l    d0,_IconBase        ;store library base
  88.  
  89.     move.l    (4).w,a6        ;put execbase in a6
  90.     lea.l    _SysInfoName,a1        ;get ptr to SysInfo.library
  91.     move.l    #2,d0            ;put ver 2 version in d0
  92.     jsr    _LVOOpenLibrary(a6)    ;open icon.library
  93.     move.l    d0,_SysInfoBase        ;store library base
  94.  
  95.     move.w    AttnFlags(a6),d0    ;get processor-type flags
  96.     btst    #AFB_68040,d0        ;check if 68040
  97.     bne    .processor_Ok        ;if so, continue startup
  98.     btst    #AFB_68030,d0        ;check if 68030
  99.     bne    .processor_Ok        ;if so, continue startup
  100.     btst    #AFB_68020,d0        ;check if 68020
  101.     bne    .processor_Ok        ;if so, continue startup
  102.  
  103.     lea.l    _SorryCPUBody,a0    ;get pointer to sorry-text
  104.     lea.l    _SorryCPUGadgets,a1    ;get pointer to sorry-gadgets
  105.     jsr    _ProgramRequest        ;create a program requester
  106.  
  107.     bra    prg_Fail        ;bail out, processor is < 020
  108.  
  109. .processor_Ok
  110.  
  111.     lea.l    _DefaultPopup,a0    ;get ptr to default popup key
  112.     move.l    a0,ptr_PopupKey        ;store the hotkey
  113.     st.l    prg_Popup        ;set program popup
  114.  
  115.     lea.l    prg_ConfigFile,a0    ;get ptr to default config-name
  116.     move.l    a0,ptr_ConfigName    ;store default config-file name
  117.  
  118.     tst.l    ptr_StartupMsg        ;check if launched from WB
  119.     beq    .NoDirWaiting        ;skip if launched from CLI
  120.  
  121.     move.l    _DosBase,a6        ;put dosbase in a6
  122.     move.l    ptr_StartupMsg,a2    ;get ptr to wbmessage
  123.     move.l    sm_ArgList(a2),a2    ;get ptr to wbstartup-message
  124.     move.l    wa_Lock(a2),d1        ;get currentdir lock
  125.     jsr    _LVOCurrentDir(a6)    ;set current directory
  126.  
  127.     tst.l    _IconBase        ;check if icon.library opened
  128.     beq    .NoDirWaiting        ;skip iconload if not opened
  129.  
  130.     move.l    _IconBase,a6        ;put iconbase in a6
  131.     move.l    wa_Name(a2),a0        ;put ptr to programname in a0
  132.     jsr    _LVOGetDiskObjectNew(a6);load the program-icon
  133.     move.l    d0,ptr_ProgramIcon    ;store whatever result
  134.  
  135.     tst.l    ptr_ProgramIcon        ;check if icon loaded
  136.     beq    .NoDirWaiting        ;skip if icon not loaded
  137.  
  138.     move.l    ptr_ProgramIcon,a4    ;put ptr to icon in a4
  139.  
  140.     move.l    do_ToolTypes(a4),a0    ;put ptr to icon tooltypes in a0
  141.     lea.l    ttp_CX_POPKEY,a1    ;get ptr to tooltype into a1
  142.     jsr    _LVOFindToolType(a6)    ;find specific tooltype
  143.     tst.l    d0            ;check if new key found
  144.     beq    .no_CX_POPKEY        ;skip if not
  145.  
  146.     move.l    d0,ptr_PopupKey        ;set a different popup key
  147.  
  148. .no_CX_POPKEY
  149.  
  150.     move.l    do_ToolTypes(a4),a0    ;put ptr to icon tooltypes in a0
  151.     lea.l    ttp_CX_POPUP,a1        ;get ptr to tooltype into a1
  152.     jsr    _LVOFindToolType(a6)    ;find specific tooltype
  153.     tst.l    d0            ;check if tooltype found
  154.     beq    .no_CX_POPUP        ;skip if not
  155.  
  156.     move.l    d0,a0            ;put toolvalue in a0
  157.     lea.l    bool_YES,a1        ;get ptr to "YES" into a1
  158.     jsr    _LVOMatchToolValue(a6)    ;try to match toolvalue
  159.     tst.l    d0            ;check if program should popup
  160.     sne    prg_Popup        ;set if it should popup
  161.  
  162. .no_CX_POPUP
  163.  
  164.     move.l    do_ToolTypes(a4),a0    ;put ptr to icon tooltypes in a0
  165.     lea.l    ttp_CFGNAME,a1        ;get ptr to tooltype into a1
  166.     jsr    _LVOFindToolType(a6)    ;find specific tooltype
  167.     tst.l    d0            ;check if tooltype found
  168.     beq    .no_CFGNAME        ;skip if not
  169.  
  170.     move.l    d0,ptr_ConfigName    ;set new config name
  171.  
  172. .no_CFGNAME
  173.  
  174. .NoDirWaiting
  175.  
  176.     * setup CX handling
  177.  
  178.     jsr    _SetupCX        ;add to CX-chain
  179.     tst.l    d0            ;check if successfull
  180.     beq    prg_Fail        ;bail out if failure
  181.  
  182.     * set win-title ptr to prg wtitle string buffer
  183.  
  184.     lea.l    prg_WindowTitle,a1    ;get ptr to win-title buffer
  185.     lea.l    MemoryDisplayWindowTags,a2;get ptr to mem-display taglist
  186.     move.l    a1,52(a2)        ;set new window-title
  187.  
  188.     * try to load the preferences
  189.  
  190.     jsr    _LoadMainPreferences    ;load preferences
  191.     tst.l    d0            ;check if prefs loaded
  192.     beq    .SetDefaults        ;skip if not
  193.  
  194.     jsr    _RetrieveSettings    ;get settings into action
  195.  
  196.     bra    .PrefsLoaded        ;skip default settings
  197.  
  198. .SetDefaults
  199.  
  200.     * set a few default preferences
  201.  
  202.     jsr    _ResetToDefaults    ;set default settings
  203.     jsr    _RetrieveSettings    ;get settings from config-area
  204.  
  205. .PrefsLoaded
  206.  
  207.     jsr    _StoreSettings        ;fill in the config-area
  208.  
  209.     tst.l    prg_Popup        ;check if program should popup
  210.     beq    .skip_Popup        ;skip if not
  211.  
  212.     jsr    _OpenGUI        ;open program GUI
  213.     tst.l    d0            ;check if gui-open succeeded
  214.     beq    prg_Fail        ;bail out if failure
  215.  
  216.     jsr    _CalculateBars        ;calculate memory-bar positions
  217.  
  218. .skip_Popup
  219.  
  220.     clr.l    prg_Terminate        ;reset termination variable
  221.  
  222.     * activate program cx-object
  223.  
  224.     move.l    _CommoditiesBase,a6    ;put commoditiesbase in a6
  225.  
  226.     move.l    ptr_ProgramBroker,a0    ;put program broker in a0
  227.     move.l    #TRUE,d0        ;set active to true
  228.     jsr    _LVOActivateCxObj(a6)    ;activate main broker
  229.  
  230.     * initialize sysinfo cpu-server
  231.  
  232.     tst.l    _SysInfoBase        ;check if SysInfo opened
  233.     beq    .no_sysinfo        ;skip if not
  234.  
  235.     move.l    _SysInfoBase,a6        ;SysInfobase in a6
  236.     jsr    _LVOInitSysInfo(a6)    ;initialize sysinfo-structure
  237.     move.l    d0,ptr_SysInfo        ;just store output
  238.     beq    .no_sysinfo        ;skip if failed
  239.  
  240.     move.l    (4).w,a6        ;execbase in a6
  241.     move.l    #SITCU_SIZEOF,d0    ;put size of cpu-usage struct in a6
  242.     move.l    #MEMF_CLEAR,d1        ;set spec. attributes to memalloc
  243.     jsr    _LVOAllocVec(a6)    ;allocate cpu-usage structure
  244.     move.l    d0,ptr_CpuUsage        ;just store pointer
  245.     beq    .no_sysinfo
  246.  
  247.     move.l    _SysInfoBase,a6        ;put sysinfobase in a6
  248.     move.l    ptr_SysInfo,a0        ;put ptr to sysinfo-structure in a0
  249.     move.l    #AN_USE_MESSAGES,d0    ;use messages, not signals
  250.     move.l    #20,d1            ;allow 20 messages to wait at port
  251.     jsr    _LVOAddNotify(a6)    ;add cpu-notify service
  252.     move.l    d0,ptr_Notify        ;store notify-service
  253.  
  254. .no_sysinfo
  255.  
  256. prg_Main    ;availmem main program loop
  257.  
  258.     * handle all user interaction and system msgs
  259.  
  260.     jsr    _HandleMemoryDisplayMsgs;handle the mem-display win msgs
  261.     tst.l    d0            ;check if any errors occured
  262.     bne    prg_Fail        ;bail out if so
  263.  
  264.     jsr    _HandleSettingsMsgs    ;handle the settings win msgs
  265.     tst.l    d0            ;check if any errors occured
  266.     bne    prg_Fail        ;bail out if so
  267.  
  268.     jsr    _HandleResizeMsgs    ;handle the resize win msgs
  269.     tst.l    d0            ;check if any errors occured
  270.     bne    prg_Fail        ;bail out if so
  271.  
  272.     jsr    _HandleCxMsgs        ;handle the CX-port messages
  273.     tst.l    d0            ;check if any errors occured
  274.     bne    prg_Fail        ;bail out if so
  275.  
  276.     jsr    _HandleSysInfoMsgs    ;handle cpu usage port
  277.  
  278.     * check if we are the top window displayed and if not, pop us to front
  279.  
  280.     tst.l    prg_AlwaysOnTop        ;check if window should depth-reorganize
  281.     beq    .noReorganize        ;skip if not
  282.  
  283.     tst.l    MemoryDisplayWnd    ;check if mem-window open
  284.     beq    .noReorganize        ;skip if not
  285.  
  286.     tst.l    prg_OnTopCounter    ;check if counter has counted enough
  287.     beq    .Reorganize        ;jump if so
  288.  
  289.     sub.l    #1,prg_OnTopCounter    ;decrease counter
  290.  
  291.     bra    .noReorganize        ;skip reorganize
  292.  
  293. .Reorganize
  294.  
  295.     move.l    prg_VBLDelay,d1        ;put how many vbl's between update
  296.     addq.l    #1,d1            ;add 1 to avoid div by zero
  297.     move.l    #150,d0            ;put 150 vbl (3 sec) in d0
  298.     divu.l    d1,d0            ;divide with update rate
  299.     move.l    d0,prg_OnTopCounter    ;store new counter
  300.  
  301.     move.l    MemoryDisplayWnd,a0    ;put ptr to memdisp-window in a0
  302.  
  303.     move.l    _IntuitionBase,a6    ;put intuitionbase in a6
  304.     move.l    MemoryDisplayWnd,a0    ;put mem-display window in a0
  305.     jsr    _LVOWindowToFront(a6)    ;bring window to front
  306.  
  307. .noReorganize
  308.  
  309.     tst.l    prg_Terminate        ;check if program should terminate
  310.     bne    prg_CloseDown        ;terminate if true
  311.  
  312.     * render the memorybars
  313.  
  314.     tst.l    prg_RenderBarsOk    ;check if init of bars succeeded
  315.     beq    .no_render        ;skip if not
  316.  
  317.     tst.l    MemoryDisplayWnd    ;check if mem-display is open
  318.     beq    .no_render        ;skip if not
  319.  
  320.     jsr    _RenderBars        ;draw memory-bars
  321.  
  322. .no_render
  323.  
  324.     * make a small wait
  325.  
  326.     move.l    _DosBase,a6        ;put dosbase in a6
  327.     move.l    prg_VBLDelay,d1        ;wait a few vbls
  328.     addq.l    #1,d1            ;convert to correct value
  329.     jsr    _LVODelay(a6)        ;go and wait (Zzz...)
  330.  
  331.     bra    prg_Main        ;loop main
  332.  
  333. prg_CloseDown
  334.  
  335.     jsr    _CloseGUI        ;close program GUI
  336.  
  337.     jsr    _QuitCX            ;remove from CX chain
  338.  
  339.     tst.l    _SysInfoBase        ;check if SysInfo.library open
  340.     beq    .no_SysInfobase        ;skip if opening failed
  341.  
  342.     move.l    _SysInfoBase,a6        ;put SysInfobase in a6
  343.  
  344.     tst.l    ptr_SysInfo        ;check if library inited ok
  345.     beq    .no_sysinfo        ;skip if not
  346.  
  347.     tst.l    ptr_Notify        ;check if notify loaded
  348.     beq    .no_notify        ;skip if not
  349.  
  350.     move.l    ptr_SysInfo,a0        ;put ptr to sysinfo in a0
  351.     move.l    ptr_Notify,a1        ;put ptr to notify in a1
  352.     jsr    _LVORemoveNotify(a6)    ;remove notify
  353.     move.l    #0,ptr_Notify        ;clear notify-pointer
  354.  
  355. .no_notify
  356.  
  357.     move.l    ptr_SysInfo,a0        ;put ptr to sysinfo-structure in a0
  358.     jsr    _LVOFreeSysInfo(a6)    ;dealloc sysinfo-structure
  359.     move.l    #0,ptr_SysInfo        ;clear sysinfo-structure ptr
  360.  
  361. .no_sysinfo
  362.  
  363.     move.l    a6,a1            ;put SysInfobase in a1
  364.     move.l    (4).w,a6        ;put execbase in a6
  365.     jsr    _LVOCloseLibrary(a6)    ;close SysInfo.library
  366.     move.l    #0,_SysInfoBase        ;reset library base
  367.  
  368. .no_SysInfobase
  369.  
  370.     tst.l    _IconBase        ;check if icon.library open
  371.     beq    .no_iconbase        ;skip if opening failed
  372.  
  373.     move.l    _IconBase,a6        ;put iconbase in a6
  374.  
  375.     tst.l    ptr_ProgramIcon        ;Check if icon was loaded
  376.     beq    .no_Icon_loaded        ;skip if not
  377.  
  378.     move.l    ptr_ProgramIcon,a0    ;put ptr to icon in a0
  379.     jsr    _LVOFreeDiskObject(a6)    ;free the icon
  380.  
  381. .no_Icon_loaded
  382.  
  383.     move.l    a6,a1            ;put iconbase in a1
  384.     move.l    (4).w,a6        ;put execbase in a6
  385.     jsr    _LVOCloseLibrary(a6)    ;close icon.library
  386.     move.l    #0,_IconBase        ;reset library base
  387.  
  388. .no_iconbase
  389.  
  390.     move.l    (4).w,a6        ;put execbase in a6
  391.     lea.l    _LibraryList,a4        ;get pointer to libs into a4
  392. .CloseLibraries
  393.     move.l    (a4)+,d0        ;get pointer to lib-string into a1
  394.     move.l    (a4)+,a1        ;get pointer to libbase-var
  395.  
  396.     tst.l    d0            ;check if no open libs left
  397.     beq    .AllLibrariesClosed    ;leave loop if so
  398.  
  399.     move.l    (a1),d1            ;put pointer to lib in d1
  400.     move.l    #0,(a1)            ;reset library base
  401.  
  402.     tst.l    d1            ;check if library open
  403.     beq    .DontCloseLib        ;skip if not
  404.  
  405.     move.l    d1,a1            ;put pointer to lib in a1
  406.  
  407.     jsr    _LVOCloseLibrary(a6)    ;close library
  408.  
  409. .DontCloseLib
  410.  
  411.     bra    .CloseLibraries        ;loop lib-closening
  412.  
  413. .AllLibrariesClosed
  414.  
  415.     move.l    (4).w,a6        ;put execbase in a6
  416.     move.l    ptr_ThisTask,a1        ;put ptr to task in a1
  417.     move.l    prg_OldPriority,d0    ;Set old priority
  418.     jsr    _LVOSetTaskPri(a6)    ;set task priority
  419.  
  420.     tst.l    ptr_StartupMsg        ;check if message saved
  421.     beq    .NoWBMessage        ;skip if launched from CLI
  422.  
  423.     move.l    (4).w,a6        ;put execbase in a6
  424.     jsr    _LVOForbid(a6)        ;Forbid multitasking (No permit needed)
  425.  
  426.     move.l    ptr_StartupMsg,a1    ;put wbmessage in a1
  427.     jsr    _LVOReplyMsg(a6)    ;reply wbmessage
  428.  
  429. .NoWBMessage
  430.  
  431.     move.l    prg_Error,d0        ;put exitcode in d0
  432.     rts                ;exit program
  433.  
  434. prg_Fail
  435.     move.l    #20,prg_Error        ;set program error
  436.     bra    prg_CloseDown        ;quit program
  437.  
  438. * subroutines
  439.  
  440. _HandleSysInfoMsgs
  441. * * * * * * * * * * * * * * * * * * * * *
  442. *                    *
  443. * Scans the sysinfo-port for messages    *
  444. * and if found, updates the contents    *
  445. * of the cpu usage bars.        *
  446. *                    *
  447. * * * * * * * * * * * * * * * * * * * * *
  448.  
  449.     movem.l    d0-a6,-(sp)
  450.  
  451.     clr.l    d7            ;reset check variable
  452.  
  453.     tst.l    ptr_Notify        ;check if sysinfo opened
  454.     beq    .no_cpuusage        ;skip if not
  455.  
  456. .GetMsgLoop
  457.     move.l    (4).w,a6        ;execbase in a6
  458.     move.l    ptr_Notify,a2        ;ptr to notify struct in a2
  459.     move.l    SIN_notify_port(a2),a0    ;put notify-port in a0
  460.     jsr    _LVOGetMsg(a6)        ;get awaitning messages
  461.     tst.l    d0            ;check if any messages received
  462.     beq    .AllMsgsGotten        ;skip if EOM
  463.  
  464.     move.l    d0,a1            ;put message in a1
  465.     jsr    _LVOReplyMsg(a6)    ;reply message
  466.  
  467.     st.l    d7            ;set update variable
  468.  
  469.     bra    .GetMsgLoop        ;loop message-retreiving
  470.  
  471. .AllMsgsGotten
  472.  
  473.     tst.l    d7            ;check if messages received
  474.     beq    .no_cpuusage        ;skip if not
  475.  
  476.     move.l    _SysInfoBase,a6        ;sysinfobase in a6
  477.     move.l    ptr_SysInfo,a0        ;put sysinfo struct in a0
  478.     move.l    ptr_CpuUsage,a1        ;put cpuusage struct in a1
  479.     jsr    _LVOGetCpuUsage(a6)    ;get current cpu-load
  480.  
  481.     move.l    ptr_CpuUsage,a0        ;put CPU-usage struct ptr in a0
  482.     move.l    SICU_used_cputime_lastsec(a0),d0    ;get amount used last second
  483.     muls.l    #100,d0            ;multiplicate with 100 (to get procent)
  484.     divs.l    SICU_used_cputime_lastsec_hz(a0),d0    ;div with hz per second
  485.     move.l    d0,prg_CPUUsage        ;store cpu-usage
  486.  
  487. .no_cpuusage
  488.  
  489.     movem.l    (sp)+,d0-a6
  490.     rts
  491.  
  492. _OpenGUI
  493. * * * * * * * * * * * * * * * * * * * * *
  494. *                    *
  495. * Locks the screen and opens the    *
  496. * memory-display window.        *
  497. *                    *
  498. * OUT:    d0 - success. (=0 FAIL)        *
  499. *                    *
  500. * * * * * * * * * * * * * * * * * * * * *
  501.  
  502.     movem.l    d0-a6,-(sp)        ;push all registers
  503.  
  504.     lea.l    MemoryDisplayWindowTags,a1;get ptr to window-tags into a1
  505.  
  506.     move.l    #WFLG_SMART_REFRESH!WFLG_GIMMEZEROZERO!WFLG_ACTIVATE,d4;set window params
  507.  
  508.     lea.l    prg_WindowTitle,a0    ;get ptr to window-title into a0
  509.     move.l    a0,52(a1)        ;set new window-title
  510.  
  511.     tst.l    prg_MinimizeBorders    ;check if borders should minimize
  512.     bne    .do_MinimizeBorders    ;skip if so
  513.  
  514.     or.l    #WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET,d4;add gadgets
  515.  
  516.     bra    .BordersOk        ;skip win-title resetting
  517.  
  518. .do_MinimizeBorders
  519.     move.l    #0,52(a1)        ;reset new window-title
  520.  
  521. .BordersOk
  522.  
  523.     tst.l    prg_RemoveBorder    ;check if borders should be removed
  524.     beq    .no_removeborders    ;skip if not
  525.  
  526.     or.l    #WFLG_BORDERLESS,d4    ;remove borders
  527.  
  528. .no_removeborders
  529.  
  530.     tst.l    prg_GoBackdrop        ;check if window should backdrop
  531.     beq    .no_backdrop        ;skip if not
  532.  
  533.     or.l    #WFLG_BACKDROP,d4    ;add backdrop flag
  534.  
  535. .no_backdrop
  536.  
  537.     move.l    d4,44(a1)        ;set window-flags
  538.  
  539.     lea.l    prg_ScreenName,a0    ;get ptr to screen-name
  540.     move.l    a0,PubScreenName    ;set new display-screen
  541.  
  542.     jsr    SetupScreen        ;initialize screen
  543.     tst.l    d0            ;check if init worked
  544.     beq    .OpenedOk        ;skip if screen locked
  545.  
  546.     jsr    CloseDownScreen        ;unlock screen
  547.  
  548.     move.l    #0,PubScreenName    ;reset screen-name
  549.     
  550.     jsr    SetupScreen        ;try again
  551.     tst.l    d0            ;check if init worked
  552.     bne    .Fail            ;bail out if failure
  553.  
  554. .OpenedOk
  555.  
  556.     move.l    Scr,a0            ;get ptr to locked screen into a0
  557.     lea.l    ResizeWindowTags,a1    ;get ptr to resize-window into a1
  558.  
  559.     move.w    sc_Width(a0),d0        ;get screen width into d0
  560.     ext.l    d0            ;extend to longword
  561.     move.l    d0,92(a1)        ;set resize-width to max
  562.     move.w    sc_Height(a0),d0    ;get screen height into d0
  563.     ext.l    d0            ;extend to longword
  564.     move.l    d0,92+8(a1)        ;set resize-height to max
  565.  
  566.     jsr    OpenMemoryDisplayWindow    ;Open AvailMem main window
  567.     tst.l    d0            ;check if window opened ok
  568.     bne    .Fail            ;bail out if failure
  569.  
  570.     jsr    _CalculateBars        ;recalculate bar structures
  571.  
  572.     move.l    _IntuitionBase,a6    ;put intutionbase in a6
  573.  
  574.     tst.l    prg_RenderBarsOk    ;check if bar-calc went ok
  575.     beq    .no_flushbuttons    ;skip if not
  576.  
  577.     tst.l    prg_FlushButtons    ;check if flushbuttons should be added
  578.     beq    .no_flushbuttons    ;skip if not
  579.  
  580.     jsr    _AddFlushGadget        ;add flushbuttons
  581.  
  582. .no_flushbuttons
  583.  
  584.     movem.l    (sp)+,d0-a6        ;pop all registers
  585.     st.l    d0            ;set exitcode to TRUE
  586.     rts                ;return
  587.  
  588. .Fail
  589.     movem.l    (sp)+,d0-a6        ;pop all registers
  590.     clr.l    d0            ;set exitcode to FALSE
  591.     rts                ;return
  592.  
  593. _CloseGUI
  594. * * * * * * * * * * * * * * * * * * * * *
  595. *                    *
  596. * Closes all program windows and    *
  597. * unlocks the screen.            *
  598. *                    *
  599. * * * * * * * * * * * * * * * * * * * * *
  600.  
  601.     movem.l    d0-a6,-(sp)        ;push all registers
  602.  
  603.     jsr    CloseResizeWindow    ;close resize window
  604.     jsr    CloseSettingsWindow    ;close settings window
  605.     jsr    CloseMemoryDisplayWindow;close main window
  606.     jsr    CloseDownScreen        ;deinitalize screen
  607.  
  608.     movem.l    (sp)+,d0-a6        ;pop all registers
  609.     rts                ;return
  610.  
  611.  
  612. _ProgramRequest
  613. * * * * * * * * * * * * * * * * * * * * *
  614. *                    *
  615. * Opens a program requester.        *
  616. *                    *
  617. * IN:                    *
  618. *    a0 - ptr to body.        *
  619. *    a1 - ptr to gadgets.        *
  620. *                    *
  621. * OUT:    d0 - gadget pressed.(=-1 FAIL)    *
  622. *                    *
  623. * * * * * * * * * * * * * * * * * * * * *
  624.  
  625.     movem.l    d1-a6,-(sp)        ;push registers
  626.  
  627.     move.l    a0,a3            ;put title-text in a3
  628.     move.l    a1,a4            ;put body-text in a4
  629.  
  630.     move.l    (4).w,a6        ;put execbase in a6
  631.     move.l    #EasyStruct_SIZEOF,d0    ;put size of EasyRequest in d0
  632.     move.l    #MEMF_CLEAR,d1        ;put memory flag CLEAR in d1
  633.     jsr    _LVOAllocVec(a6)    ;Alloc a EasyRequest
  634.     move.l    d0,a2            ;store EasyRequest
  635.     beq    .Fail            ;bail our if failure
  636.  
  637.     move.l    _IntuitionBase,a6    ;put intuitionbase in a6
  638.  
  639.     move.l    #EasyStruct_SIZEOF,es_StructSize(a2)
  640.                     ;put size in es_StructSize
  641.  
  642.     lea.l    _RequesterTitle,a0    ;get ptr to requester title text
  643.     move.l    a0,es_Title(a2)        ;put title in es_Title
  644.     move.l    a3,es_TextFormat(a2)    ;put body in es_TextFormat
  645.     move.l    a4,es_GadgetFormat(a2)    ;put gadgets in es_GadgetFormat
  646.     move.l    a2,a5            ;put EasyRequest in a5
  647.     move.l    MemoryDisplayWnd,a0    ;put mem-display window in a0
  648.     move.l    a5,a1            ;put EasyRequest in a1
  649.     sub.l    a2,a2            ;clear IDCMP-flags
  650.     sub.l    a3,a3            ;clear ArgList
  651.     move.l    a2,a0            ;put EasyRequest in a0
  652.     jsr    _LVOEasyRequestArgs(a6)    ;produce a EasyRequest
  653.  
  654.     move.l    d0,d7            ;store answer in d7
  655.  
  656.     move.l    (4).w,a6        ;put execbase in a6
  657.     move.l    a5,a1            ;put EasyRequest in a1
  658.     jsr    _LVOFreeVec(a6)        ;Free EasyRequest
  659.  
  660.     move.l    d7,d0            ;put gadgetpressed in d0
  661.  
  662.     movem.l    (sp)+,d1-a6        ;pop registers
  663.     rts                ;return
  664. .Fail
  665.     movem.l    (sp)+,d1-a6        ;pop registers
  666.     moveq.l    #-1,d0            ;return ERROR (No IDCMPFlag occur.)    
  667.     rts                ;return
  668.  
  669. _StringCopy
  670. * * * * * * * * * * * * * * * * * * * * *
  671. *                    *
  672. * Copies a null-terminated string.    *
  673. *                    *
  674. * IN:    a0 - source string.        *
  675. *    a1 - dest string.        *
  676. *                    *
  677. * OUT:    d0 - ptr to end of dest string.    *
  678. *                    *
  679. * * * * * * * * * * * * * * * * * * * * *
  680.  
  681.     movem.l    d1-a6,-(sp)        ;push all registers
  682.  
  683. .CopyLoop
  684.     move.b    (a0)+,d0        ;read input char
  685.     move.b    d0,(a1)+        ;write output char
  686.     tst.b    d0            ;check if EOS
  687.     bne    .CopyLoop        ;loop if not
  688.  
  689.     move.l    a1,d0            ;put ptr to end of dest string in d0
  690.  
  691.     movem.l    (sp)+,d1-a6        ;pop all registers
  692.     rts                ;return
  693.  
  694.     section    data,data        ;availmem data section
  695.  
  696. _LibraryList
  697.     dc.l    _DosName,_DosBase
  698.     dc.l    _GfxName,_GfxBase
  699.     dc.l    _IntuitionName,_IntuitionBase
  700.     dc.l    _GadToolsName,_GadToolsBase
  701.     dc.l    _CommoditiesName,_CommoditiesBase
  702.     dc.l    0            ;end of list
  703.  
  704. * library names
  705.  
  706. _DosName        dc.b    "dos.library",0
  707. _GfxName        dc.b    "graphics.library",0
  708. _IntuitionName        dc.b    "intuition.library",0
  709. _GadToolsName        dc.b    "gadtools.library",0
  710. _CommoditiesName    dc.b    "commodities.library",0
  711. _IconName        dc.b    "icon.library",0
  712. _SysInfoName        dc.b    "SysInfo.library",0
  713.  
  714. * requester strings
  715.  
  716. _RequesterTitle        dc.b    "AvailMem Request",0
  717.  
  718. * Tooltype strings
  719.  
  720. ttp_CX_POPUP        dc.b    "CX_POPUP",0
  721. ttp_CX_POPKEY        dc.b    "CX_POPKEY",0
  722. ttp_CX_PRIORITY        dc.b    "CX_PRIORITY",0
  723. ttp_CONFIG        dc.b    "CONFIG",0
  724. ttp_CFGNAME        dc.b    "CFGNAME",0
  725.  
  726. * default config name
  727.  
  728. prg_ConfigFile        dc.b    "AvailMem",0
  729. prg_ConfigAttach    dc.b    ".config",0
  730.  
  731. * boolean true variables
  732.  
  733. bool_YES        dc.b    "YES",0
  734.  
  735. * requester text
  736.  
  737. _SorryCPUBody        dc.b    "Sorry, this program\n"
  738.             dc.b    " requires at least\n"
  739.             dc.b    "     a MC68020",0
  740. _SorryCPUGadgets    dc.b    "Ok",0
  741.  
  742.     section    bss,bss            ;availmem bss section
  743.  
  744. * library bases
  745.  
  746. _DosBase        ds.l    1
  747. _GfxBase        ds.l    1
  748. _IntuitionBase        ds.l    1
  749. _GadToolsBase        ds.l    1
  750. _CommoditiesBase    ds.l    1
  751. _IconBase        ds.l    1
  752. _SysInfoBase        ds.l    1
  753.  
  754. * program variables
  755.  
  756. ptr_ThisTask        ds.l    1    ;ptr to Task structure
  757. ptr_StartupMsg        ds.l    1    ;ptr to WBStartup message
  758. ptr_TempMsg        ds.l    1    ;ptr to any message
  759. ptr_SysInfo        ds.l    1    ;ptr to sysinfo structure
  760. ptr_CpuUsage        ds.l    1    ;ptr to cpuusage structure
  761. ptr_Notify        ds.l    1    ;ptr to notify structure
  762. ptr_ProgramIcon        ds.l    1    ;ptr to program icon
  763. ptr_ConfigName        ds.l    1    ;ptr to config-file name
  764.  
  765. prg_Error        ds.l    1    ;program exitcode
  766. prg_Terminate        ds.l    1    ;program terminate variable
  767. prg_OldPriority        ds.l    1    ;program old priority
  768. prg_OnTopCounter    ds.l    1    ;counter that controls 'on top' feature
  769.